﻿using Entity.ERP.DTO.SaleOrder;
using Entity.ERP.View.SaleOrder;
using Entity.ERP.View.SaleOrderItem;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.ERP;

namespace AnQinManagermentBackendAPI.Controller.ERP
{
    /// <summary>
    /// 编码规则表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class SaleOrderController : ControllerBase
    {
        /**
         * 编码规则业务接口
         */
        private readonly SaleOrderService _saleOrderService;

        /**
         * 构造函数注入
         */
        public SaleOrderController(SaleOrderService saleOrderService)
        {
            _saleOrderService = saleOrderService;
        }

        /// <summary>
        /// 获取销售订单列表
        /// </summary>
        /// <param name="saleOrderSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(SaleOrderView), 200)]
        public async Task<IActionResult> GetSaleOrderList([FromQuery] SaleOrderSearchDTO saleOrderSearchDTO)
        {
            var response = await _saleOrderService.GetSaleOrderList(saleOrderSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取销售订单子单列表
        /// </summary>
        /// <param name="saleOrderItemSearchDTO"></param>
        [HttpGet("item")]
        [ProducesResponseType(typeof(SaleOrderItemView), 200)]
        public async Task<IActionResult> GetSaleOrderItemList([FromQuery] SaleOrderItemSearchDTO saleOrderItemSearchDTO)
        {
            var response = await _saleOrderService.GetSaleOrderItemList(saleOrderItemSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取销售订单源单列表
        /// </summary>
        /// <param name="saleOrderSourceSearchDTO"></param>
        [HttpGet("source")]
        [ProducesResponseType(typeof(SaleOrderSourceView), 200)]
        public async Task<IActionResult> GetSaleOrderSourceList([FromQuery] SaleOrderSourceSearchDTO saleOrderSourceSearchDTO)
        {
            var response = await _saleOrderService.GetSaleOrderSourceList(saleOrderSourceSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增销售订单
        /// </summary>
        /// <param name="saleOrderAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddSaleOrder([FromBody] SaleOrderAddDTO saleOrderAddDTO)
        {
            var response = await _saleOrderService.AddSaleOrder(saleOrderAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新销售订单
        /// </summary>
        /// <param name="saleOrderUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutSaleOrder([FromBody] SaleOrderUpdateDTO saleOrderUpdateDTO)
        {
            var response = await _saleOrderService.PutSaleOrder(saleOrderUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除销售订单
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteSaleOrder(string Id)
        {
            var response = await _saleOrderService.DeleteSaleOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核通过销售订单
        /// </summary>
        [HttpPost("Pass")]
        public async Task<IActionResult> PassSaleOrder(string Id)
        {
            var response = await _saleOrderService.PassSaleOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核不通过销售订单
        /// </summary>
        [HttpPost("UnPass")]
        public async Task<IActionResult> UnPassSaleOrder(string Id)
        {
            var response = await _saleOrderService.UnPassSaleOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核通过销售订单
        /// </summary>
        [HttpPost("CancelPass")]
        public async Task<IActionResult> CancelPassSaleOrder(string Id)
        {
            var response = await _saleOrderService.CancelPassSaleOrder(Id);
            return StatusCode(response.Status, response);
        }
    }
}
